package com.cskaoyan._01basic._08loop._02test;

import org.junit.Test;

/**
 * @author Macro_Ray
 * @since 2024/3/4 11:12
 */
public class _02For_02 {
    public static void main(String[] args) {
        // 获取一个范围中每个数据的和

        int sum1 = 0;
        for (int i = 0; i < 10; i++) {
            sum1 += i;
        }
        System.out.println("sum1=" + sum1);

        int[] nums = new int[]{1, 2, 3, 4, 5};
        int sum2 = 0;
        for (int j = 0; j < 5; j++) {
            //System.out.println(j);
            sum2 += nums[j];
        }
        System.out.println("sum2=" + sum2);

    }

    @Test
    public void test2() {
        // 求 1-100 之间的偶数和

        int sum = 0;
        for (int i = 0; i <= 100; i++) {
            if (i % 2 == 0) {
                sum += i;
            }
        }
        System.out.println(sum);
    }


}